<?php
// -------
// SELECT
// -------
// "Prepare" an sql statement
$query = new SDBStatement( "SELECT * FROM cars WHERE colour = :colour" );

// Bind a value to :colour
$query->bindValue( ':colour', 'red' );

// Execute the query
$query->execute();

// Fetch into a ModelCollection of Car objects
$cars = $query->fetchAllInto( 'Car' );

// If we only wanted the first car returned
$car = $query->fetchInto( 'Car' );


// -------
// INSERT
// -------
// Create an object for using with bindObject (although we could bind each value
// individually if we prefer
$car = new Car();
$car->colour = 'red';
$car->brand  = 'Alfa Romeo';

// "Prepare" an sql statement
$query = new SDBStatement( "INSERT INTO cars (colour, brand) VALUES (:colour, :brand)" );

// Bind the object's properties to the query placeholders
$query->bindObject( $car );

// Execute the statement
$query->execute();

// The autogenerated itemName is
echo "ID: ", SDBStatement::LastInsertId();


// -------
// UPDATE
// -------
// "Prepare" an sql statement
$query = new SDBStatement( "UPDATE cars SET colour = :colour WHERE brand = :brand" );

// Bind when executing:
$query->execute(array(
    ':colour'   => 'red',
    ':brand'    => 'Alfa Romeo'
));


// -------
// DELETE
// -------
$query = new SDBStatement( "DELETE FROM cars WHERE colour = :colour" );

// Bind a value to :colour
$query->bindValue( ':colour', 'red' );

// Execute the query
$query->execute();

// The query "SELECT * FROM cars WHERE colour = red'" will now return zero results